import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ThemeTest extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _ThemeTest();
  }
}

class _ThemeTest extends State<ThemeTest> {
  Color _color = Colors.teal;

  @override
  Widget build(BuildContext context) {
    ThemeData theme = Theme.of(context);
    // TODO: implement build
    return Theme(
        data: ThemeData(
            primarySwatch: _color,
            iconTheme: IconThemeData(color: _color),
            textTheme: TextTheme(body1: TextStyle(color: _color))),
        child: Scaffold(
          appBar: AppBar(
            title: Text('主题测试'),
          ),
          body: Center(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Row(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[Icon(Icons.favorite), Text("跟随系统改变颜色")],
                ),
                Theme(
                    data: theme.copyWith(
                        iconTheme: IconThemeData(color: Colors.green),
                        textTheme:
                            TextTheme(body1: TextStyle(color: Colors.green))),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[Icon(Icons.favorite), Text("不改变颜色")],
                    )),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(onPressed: () {
            setState(() {
              _color = _color == Colors.teal?Colors.deepOrange:Colors.teal;
            });
          }, child: Icon(Icons.color_lens),),
        ));
  }
}
